<template>
  <header>
    <div class="header-left">
      <el-button type="primary" icon="el-icon-menu" size="mini" plain @click="asideClick"></el-button>
      <span>首页</span>
    </div>
    <el-dropdown @command="handleCommand">
      <span class="el-dropdown-link">
        <img :src="userImg" class="user-sculpture">
      </span>
      <el-dropdown-menu slot="dropdown">
        <p style="font-size: 1.5vw;color: #49515b;text-indent: 10px;margin-bottom: 10px">用户:{{ username }}</p>
        <el-dropdown-item icon="el-icon-user" command="toUserCenter">个人中心</el-dropdown-item>
        <el-dropdown-item icon="el-icon-turn-off" command="loginOut">退出</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </header>
</template>

<script>
export default {
  name: "Common-header",
  data() {
    return {
      userImg: require('@/assets/user.png')
    }
  },
  computed:{
    username(){return this.$store.getters['loginUser/getUsername']}
  },
  methods: {
    handleCommand(command) {
      if (command === 'toUserCenter') {
        this.$router.push('/usercenter');
      }else if (command==='loginOut'){
        window.localStorage.removeItem('TOKEN');
        this.$router.push('/login')
      }

    },
    asideClick() {
      console.log('触发菜单事件')
      this.$store.commit('moduleHeader/updateAsideStatus');
      //console.log(this.$store.hasModule('moduleHeader'))
    }
  }
}
</script>

<style scoped lang="less">
.el-dropdown {
  width: 50px;
  height: 50px;
}

.header-left {
  box-sizing: border-box;
  width: 150px;
  height: 50px;
  display: flex;
  justify-content: space-around;
  align-items: center;

  span {
    color: white;
    font-weight: 400;
  }
}

header {
  display: flex;
  justify-content: space-between;
  align-content: center;
  margin-top: 5px;
}

.user-sculpture {
  height: 45px;
  width: 45px;
  border-radius: 22.5px;
}
</style>